package top.huntwolf.admin.pojo.orderEntity;


import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import top.huntwolf.admin.common.enums.EnumValue;
import top.huntwolf.admin.common.enums.OrderStatus;
import top.huntwolf.admin.common.enums.OrderType;
import top.huntwolf.admin.pojo.Address;
import top.huntwolf.admin.pojo.User;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Order implements Serializable {

    @NotNull(message = "order_id cannot be null")
    private String orderId;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    private String money;

    private OrderStatus orderStatus;

    private OrderType orderType;

    private String openId;

    private Integer addressId;

    private User user;

    private Address address;

    private String remark;

    @ApiModelProperty("剩余时间")
    private long time;

    private Integer storeId;

    private List<OrderBook> books;


    public void setOrderStatus(Object orderStatus){
        if (orderStatus instanceof OrderStatus){
            this.orderStatus = (OrderStatus) orderStatus;
        }else{
            this.orderStatus = EnumValue.valueOf(OrderStatus.class,orderStatus);
        }
    }

    public void setOrderType(Object orderType){
        if (orderType instanceof OrderType){
            this.orderType = (OrderType) orderType;
        }else {
            this.orderType = EnumValue.valueOf(OrderType.class,orderType);
        }
    }
}
